import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import direct_to from '@dfeidao/atom-web/url/direct-to';
export default async function a003(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	// 点击内容
	console.log('点击消息内容');
	const target = e.currentTarget as HTMLDivElement;
	const msgid = target.getAttribute('fd-value');
	const msg_page_url = target.getAttribute('fd-value1');
	const msg_cont = target.getAttribute('fd-value2');
	console.log(msgid);
	console.log(msg_page_url);
	console.log(msg_cont);
	const productid = get(fd, 'productid');
	const query = {
		productid,
		msgid
	};
	if (msg_page_url) {

		const data = await nodejs<{ res: Array<{ param_name: string, param_datatype: string, param_value: string }> }>('common/zjc-000005/s003', query);
		console.log('data.res:');
		console.log(data.res);
		if (data.res.length > 0) {
			const name = data.res[0].param_name as string;
			const value = data.res[0].param_value;
			direct_to(msg_page_url, { [name]: value }, true);

			const res = await nodejs<{ code: number }>('common/zjc-000005/s004', query);
			console.log(res);
			fire('zjc-000005', 'a001');
			// await a001(fd);
		} else {
			fire('zjc-000006', 'a001', msg_cont);
			const res1 = await nodejs<{ code: number }>('common/zjc-000005/s004', query);
			console.log(res1);
		}


	} else {
		fire('zjc-000006', 'a001', msg_cont);
		const res1 = await nodejs<{ code: number }>('common/zjc-000005/s004', query);
		console.log(res1);
	}


}
